package com.jinzhi.jzweb.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jinzhi.api.exception.IFastApiException;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.type.ApiEnumError;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.TrackDrawDO;
import com.jinzhi.jzweb.service.TrackDrawNanNingService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 
 * <pre>
 *     南宁婴幼儿保育赛道抽签功能
 * </pre>
 * <small> 2023-10-16 16:36:18 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/trackDrawNanNing")
public class TrackDrawNanNingController extends BaseController {
	@Autowired
	private TrackDrawNanNingService trackDrawNanNingService;
	
	@GetMapping()
	String TrackDraw(){
	    return "jzweb/trackDrawNanNing/trackDrawNanNing";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public Result<TrackDrawDO> list(TrackDrawDO trackDrawDTO){

		return trackDrawNanNingService.selectDraw(trackDrawDTO);
	}

	@ResponseBody
	@GetMapping("/signComList")
	public Result<List<TrackDrawDO>> signComList(){

		return trackDrawNanNingService.signComList();
	}

	/**
	 * 根据状态和页码修改抽签状态
	 * @param trackDrawDO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/updateByFlag")
	public Result<?> updateByFlag(TrackDrawDO trackDrawDO){
		trackDrawNanNingService.updateByFlag(trackDrawDO);
		return Result.ok();
	}


	@ResponseBody
	@GetMapping("/updateSign")
	public Result<?> updateSign(){
		trackDrawNanNingService.updateSign();
		return Result.ok();
    }

	/**
	 * 查询上次的抽签结果
	 */
	@ResponseBody
	@GetMapping("/trackList")
	public Result<TrackDrawDO> trackList(TrackDrawDO trackDrawDTO){

		return trackDrawNanNingService.trackList(trackDrawDTO);
	}




	/**
	 * 导出抽签结果信息
	 *
	 * @param response
	 */
	@Log("导出抽签结果信息")
	@RequestMapping("/downloadImportTemplate")
	@ResponseBody
	public void downloadImportTemplate(HttpServletRequest request, HttpServletResponse response, TrackDrawDO trackDrawDTO) {
		Wrapper<TrackDrawDO> wrapper = new EntityWrapper<>();
		wrapper.orderBy(true,"sort");
		List<TrackDrawDO> trackDrawDOS = trackDrawNanNingService.selectList(wrapper);
		if (trackDrawDOS != null && trackDrawDOS.size() > 0) {
			//导出操作
			EasyPoiUtil.exportExcel(trackDrawDOS, "广西婴幼儿保育抽签信息", "广西婴幼儿保育抽签信息", TrackDrawDO.class,  "广西婴幼儿保育抽签信息", response);
		} else {
			throw new IFastApiException(ApiEnumError.NOTBATCHSTU.getCodeStr());
		}
	}

}
